﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Csla.Xaml;
using Accounting.Library;
using System.Windows.Data;
using BusinessConfiguration;

namespace csla4Skeleton.UI.SL.NghiepVu.TaiSanCoDinh.TSCD_KeKhai
{
    public class TSCD_KeKhai_ListViewModel : ViewModel<TSCD_KeKhaiList>
    {
        public event EventHandler LoadCompleted;
        public TSCD_KeKhai_ListViewModel(string mode)
        {
            BeginRefresh("GetTSCD_KeKhaiList", mode);
        }

        public void GetTSCD_KeKhai_ListViewModel(string mode)
        {
            BeginRefresh("GetTSCD_KeKhaiList", mode);
        }

        protected override void OnRefreshed()
        {
            base.OnRefreshed();
            if (Model != null)
            {
                
                if (LoadCompleted != null)
                {
                    LoadCompleted(this, new EventArgs());
                }
            }
        }

        public static readonly DependencyProperty SelectedItemProperty =
          DependencyProperty.Register("SelectedItem", typeof(TSCD_KeKhaiInfo), typeof(TSCD_KeKhai_ListViewModel), null);
        public TSCD_KeKhaiInfo SelectedItem
        {
            get { return (TSCD_KeKhaiInfo)GetValue(SelectedItemProperty); }
            set { SetValue(SelectedItemProperty, value); }
        }

        public void DeleteTSCD_KeKhai(object sender, ExecuteEventArgs e)
        {
            if (e.MethodParameter != null)
            {
                //cast parameter
                string parameter = e.MethodParameter.ToString();
                this.IsBusy = true;
                Accounting.Library.TSCD_KeKhai.DeleteTSCD_KeKhai(int.Parse(parameter), (o, ex) =>
                {
                    BeginRefresh("GetTSCD_KeKhaiList", BusinessConfiguration.Configuration.GridViewFetchMode);
                });
                this.IsBusy = false;
            }
        }
    }
}






